/**
 * Created by xiu on 2017/4/4.
 */
import React from "react";
import { DatePicker} from 'antd';
import moment from 'moment';
const dateFormat = 'YYYY-MM-DD';
export default class Creatorder_StepThree extends React.Component{
    constructor(props){
        super(props);
        this.state={
            islast:false,
            isfrist:false,
            data:'',
            context:this.props.context
        }
    }

    componentWillMount(){
        let totallenght = this.props.totallenght
        if(totallenght == 1){
            this.setState({
                isfrist:true,
                islast:true,
            });
            return;
        }

        if(((this.props.index+1) == totallenght)){
            this.setState({
                islast:true,
            });
        }

        if(this.props.index == 0){
            this.setState({
                isfrist:true,
            });
        }

    }

    addremarkitemlist(){
        this.props.addremarkitemlist();
    }

    deremarkteitem(index){
        this.props.deremarkteitem(index);
    }

    showcalendar(){
        this.props.showcalendar();
    }

    chosedate(date, dateString){
        let context = this.state.context;
        context.data= dateString;
        this.setState({
            context:context
        });
    }

    render(){
        return (
            <thead>
                <tr className="order_from_trcontext">
                    <td className="order_frorm_td order_frorm_td_three_time">
                        <div className="order_frorm_td_div">
                            <DatePicker className="ant-calendar-picker-input" onChange={this.chosedate.bind(this)} ref={'dpicker'} format={dateFormat}
                                        placeholder="请选择日期"
                                        defaultValue={this.state.context.data?moment(this.state.context.data, dateFormat):''}/>
                        </div>
                        </td>
                    <td className="order_frorm_td order_frorm_td_three_num"><input className="order_from_inputcontext"/></td>
                    <td className="order_frorm_td order_frorm_td_three_remark"><input className="order_from_inputcontext"/></td>
                    <td className="order_frorm_td order_from_td_delandadd" >
                        <span className={this.state.islast?'order_from_sp_add':'order_from_sp_addmiss'} onClick={this.addremarkitemlist.bind(this)}>+</span>
                        <span className={this.state.isfrist?"order_from_sp_minusmiss":"order_from_sp_minus"} onClick={this.deremarkteitem.bind(this,this.props.index)}>-</span>
                    </td>
                </tr>
            </thead>
        )
    }
}